<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">var AnimationProcess = require(&quot;./AnimationProcess&quot;);

var dataUtil = require(&quot;../core/utils/data_structure_util&quot;);

<span id='qrenderer-animation-Animatable'>/**
</span> * @class qrenderer.animation.Animatable
 * 
 * 动画接口类，在 Element 类中 mixin 此类提供的功能，为元素提供动画功能。
 * 混入 Animatable 的类必须同时混入 Eventful ，因为动画过程中需要使用事件机制。
 * 
 * @docauthor 大漠穷秋 &lt;damoqiongqiu@126.com&gt;
 */

<span id='qrenderer-animation-Animatable-method-constructor'>/**
</span> * @abstract
 * @method constructor Animatable
 */
var Animatable = function Animatable() {
<span id='qrenderer-animation-Animatable-property-animationProcessList'>  /**
</span>   * @property {qrenderer.animation.AnimationProcess}
   * @readOnly
   */
  this.animationProcessList = [];
};

Animatable.prototype = {
  constructor: Animatable,

<span id='qrenderer-animation-Animatable-method-animate'>  /**
</span>   * @method 
   * 创建动画实例
   * @param {String} path The path to fetch value from object, like &#39;a.b.c&#39;.
   * @param {Boolean} [loop=false] Whether to loop animation.
   * @return {qrenderer.animation.AnimationProcess}
   */
  animate: function animate() {
    var animatable = this;
    var animationProcess = new AnimationProcess(animatable);
    animationProcess.on(&#39;done&#39;, function () {
      animatable.removeAnimationProcess(animationProcess);
    });
    animationProcess.on(&#39;stop&#39;, function () {
      animatable.removeAnimationProcess(animationProcess);
    });
    animatable.animationProcessList.push(animationProcess);

    if (animatable.__qr) {
      // If animate after added to the qrenderer
      animatable.__qr.globalAnimationMgr.addAnimatable(animatable);
    }

    return animationProcess;
  },

<span id='qrenderer-animation-Animatable-method-stopAnimation'>  /**
</span>   * @method
   * 停止动画
   * @param {Boolean} forwardToLast If move to last frame before stop
   */
  stopAnimation: function stopAnimation() {
    var forwardToLast = arguments.length &gt; 0 &amp;&amp; arguments[0] !== undefined ? arguments[0] : false;
    this.animationProcessList.forEach(function (ap, index) {
      ap.stop(forwardToLast);
    });
    this.animationProcessList.length = 0;
    return this;
  },

<span id='qrenderer-animation-Animatable-method-removeAnimationProcess'>  /**
</span>   * @method removeAnimationProcess
   * 删除动画片段
   * @param {AnimationProcess} animationProcess
   */
  removeAnimationProcess: function removeAnimationProcess(animationProcess) {
    var index = this.animationProcessList.indexOf(animationProcess);

    if (index &gt;= 0) {
      this.animationProcessList.splice(index, 1);
    }
  }
};
var _default = Animatable;
module.exports = _default;</pre>
</body>
</html>
